import 'package:hive/hive.dart';

@HiveType(typeId: 2)
class TodoItem extends HiveObject {
  @HiveField(0)
  String content; //内容
  @HiveField(1)
  int level; //优先级
  @HiveField(2)
  String createAt; //创建日期
  @HiveField(3)
  String completionAt; //完成日期

  TodoItem({this.content = "", this.level = 0, this.createAt = "", this.completionAt = ""});

  @override
  String toString() {
    return "content:$content, level:$level, createAt:$createAt, completionAt:$completionAt";
  }
}

class TodoItemAdapter extends TypeAdapter<TodoItem> {
  @override
  TodoItem read(BinaryReader reader) {
    return TodoItem(
        content: reader.readString(),
        level: reader.readInt(),
        createAt: reader.readString(),
        completionAt: reader.readString());
  }

  @override
  int get typeId => 0; //0 到 223 之间

  @override
  void write(BinaryWriter writer, TodoItem obj) {
    writer.writeString(obj.content);
    writer.writeInt(obj.level);
    writer.writeString(obj.createAt);
    writer.writeString(obj.completionAt);
  }
}
